import {DICT} from './dict'
//存储数据
const setStorage =(key,value)=>{
    if(key in DICT === false){
        console.error('数据字典里未添加')
        return
    }
    if(typeof value === 'object'){
        value = JSON.stringify(value)
    }
    localStorage.setItem(key,value)
}
 
//获取数据
const getStorage = (key)=>{
    if(key in DICT === false){
        console.error('数据字典里未添加')
        return
    }
    const data = localStorage.getItem(key)
    try {
        return JSON.parse(data)    
    } catch (error) {
        return data  
    }
}
 
//删除数据
const removeStorage = (key)=>{
    if(key in DICT === false){
        console.error('数据字典里未添加')
        return
    }
    localStorage.removeItem(key)
}
 
 
//导出方法
export {
    setStorage,
    getStorage,
    removeStorage
}